package com.ruoyi.facility.service.impl;

import java.util.List;

import com.ruoyi.commerce.domain.CommerceInfoFac;
import com.ruoyi.commerce.service.ICommerceInfoFacService;
import com.ruoyi.commerce.service.ICommerceInfoService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.facility.mapper.CommerceFacilityMapper;
import com.ruoyi.facility.domain.CommerceFacility;
import com.ruoyi.facility.service.ICommerceFacilityService;

/**
 * 设施用品Service业务层处理
 * 
 * @author zhezhi
 * @date 2022-10-01
 */
@Service
public class CommerceFacilityServiceImpl implements ICommerceFacilityService 
{
    @Autowired
    private CommerceFacilityMapper commerceFacilityMapper;

    @Autowired
    private ICommerceInfoFacService infoFacService;

    @Autowired
    private ICommerceInfoService infoService;

    /**
     * 查询设施用品
     * 
     * @param facilityId 设施用品主键
     * @return 设施用品
     */
    @Override
    public CommerceFacility selectCommerceFacilityByFacilityId(Long facilityId)
    {
        CommerceFacility commerceFacility = commerceFacilityMapper.selectCommerceFacilityByFacilityId(facilityId);
        CommerceInfoFac commerceInfoFac = new CommerceInfoFac();
        commerceInfoFac.setFacId(facilityId);
        List<CommerceInfoFac> commerceInfoFacs = infoFacService.selectCommerceInfoFacList(commerceInfoFac);
        for(CommerceInfoFac i:commerceInfoFacs){
            commerceFacility.setCommerceId(i.getInfoId());
        }
        return commerceFacility;
    }

    /**
     * 查询设施用品列表
     * 
     * @param commerceFacility 设施用品
     * @return 设施用品
     */
    @Override
    public List<CommerceFacility> selectCommerceFacilityList(CommerceFacility commerceFacility)
    {
        return commerceFacilityMapper.selectCommerceFacilityList(commerceFacility);
    }

    /**
     * 新增设施用品
     * 
     * @param commerceFacility 设施用品
     * @return 结果
     */
    @Override
    public int insertCommerceFacility(CommerceFacility commerceFacility)
    {
        commerceFacility.setCreateTime(DateUtils.getNowDate());
        int i = commerceFacilityMapper.insertCommerceFacility(commerceFacility);
        CommerceFacility commerceFacility1 = commerceFacilityMapper.selectByEnd();
        CommerceInfoFac infoFac = new CommerceInfoFac();
        infoFac.setFacId(commerceFacility1.getFacilityId());
        infoFac.setInfoId(commerceFacility.getCommerceId());
        int i1 = infoFacService.insertCommerceInfoFac(infoFac);
        return i;
    }

    /**
     * 修改设施用品
     * 
     * @param commerceFacility 设施用品
     * @return 结果
     */
    @Override
    public int updateCommerceFacility(CommerceFacility commerceFacility)
    {
        commerceFacility.setUpdateTime(DateUtils.getNowDate());
        CommerceInfoFac infoFac = new CommerceInfoFac();
        infoFac.setFacId(commerceFacility.getFacilityId());
        infoFac.setInfoId(commerceFacility.getCommerceId());
        int i1 = infoFacService.updateFacToCommerceInfo(infoFac);
        return commerceFacilityMapper.updateCommerceFacility(commerceFacility);
    }

    /**
     * 批量删除设施用品
     * 
     * @param facilityIds 需要删除的设施用品主键
     * @return 结果
     */
    @Override
    public int deleteCommerceFacilityByFacilityIds(Long[] facilityIds)
    {
//        int i = infoFacService.deleteCommerceInfoFacByInfoIds(facilityIds);

        return commerceFacilityMapper.deleteCommerceFacilityByFacilityIds(facilityIds);
    }

    /**
     * 删除设施用品信息
     * 
     * @param facilityId 设施用品主键
     * @return 结果
     */
    @Override
    public int deleteCommerceFacilityByFacilityId(Long facilityId)
    {

        return commerceFacilityMapper.deleteCommerceFacilityByFacilityId(facilityId);
    }
}
